package com.swallow.cloud.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.swallow.cloud.common.model.R;
import com.swallow.cloud.entity.User;
import com.swallow.cloud.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户管理
 * @Author: L.swallow
 * @Date: 2018/12/29 15:00
 */
@Controller
@RequestMapping("/${adminPath}/user")
public class SysUserController {

    @Autowired
    private UserService userService;

    @RequestMapping("manager")
    public String manager(){
        return "/modules/user/user";
    }

    @RequestMapping("list")
    @ResponseBody
    public Object list(User user, Integer current, Integer size){
        IPage<User> page=userService.page(new Page<>(current,size),new QueryWrapper<>(user));
        return page;
    }


    @RequestMapping("info/{id}")
    @ResponseBody
    public Object info(@PathVariable String id){
        User user =userService.getById(id);
        List<String> idList=new ArrayList<>();
        idList.add("1");
        user.setRoleIdList(idList);
        return R.success(user);
    }

    @RequestMapping("save")
    @ResponseBody
    public Object save(@RequestBody User user, HttpServletRequest request){
        user.insertOrUpdate();
        return R.success();
    }

}
